package com.example.hello.client.Hero;

import com.example.hello.BootstrapHero;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapHero.class)
public class BootstrapHeroConnector extends AbstractComponentContainerConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapHero.class);
    }

    @Override
    public BootstrapHeroState getState() {
        return (BootstrapHeroState) super.getState();
    }

    @Override
    public VBootstrapHero getWidget() {
        return (VBootstrapHero) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapHeroState state = getState();

        VBootstrapHero hero = getWidget();

        for (Connector connector : state.getWidgets()) {
            hero.add(((ComponentConnector) connector).getWidget());
        }
    }

    @Override
    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

    }

    @Override
    public void updateCaption(ComponentConnector connector) {

    }

}